package biz.ws.ws;

import biz.ws.ws.exception.MessageConvertException;
import com.alibaba.fastjson.JSON;

/**
 * @创建人 xiaojiancheng
 * @时间 2020/1/8
 * @描述 $k$
 */
public class DefaultMessageConvertImpl implements MessageConvert {
    @Override
    public String encode(Message message) throws MessageConvertException {
        return JSON.toJSONString(message);
    }

    @Override
    public Message decode(String origin) throws MessageConvertException {
        try{
            Message message = JSON.parseObject(origin, Message.class);
            return message;
        }catch (Exception e){
            throw new MessageConvertException();
        }
    }
}
